import { DataTypes } from 'sequelize'

import db from '../config/db.js';

//创建模型(模型.默认表名users)
const User = db.define('user', {
  //id 会被swql自动创建
  username: {
    type: DataTypes.STRING,
    allowNull: false,
    unique: true
  },
  password: {
    type: DataTypes.STRING,
    allowNull: false
  },
  email: {
    type: DataTypes.STRING,
    allowNull: true,
  },
  phone: {
    type: DataTypes.STRING,
    allowNull: true,
    unique: true
  },
  lastLoginTime: {
    type: DataTypes.DATE,
    allowNull: true
  },
  loginTimes: {
    type: DataTypes.INTEGER,
    allowNull: true,
    defaultValue: 0
  }
}, {
  //表名
  tableName: "user",
  paranoid: true    //软删除
})

//同步表
// User.sync({ alter: true }).then(() => {
//   console.log('user表创建成功')
// })

export default User